package cn.hgd11.security.common;

import cn.hgd11.security.enums.GlobalCodeEnum;
import lombok.Data;
import org.springframework.util.Assert;

import java.io.Serializable;

/**
 * @author wangkaige
 * @param <T> 数据泛型
 */
@Data
public class CommonResult<T> implements Serializable {

    private String code;
    /**
     * 返回数据
     */
    private T data;

    private String msg;

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult<>();
        result.code = GlobalCodeEnum.GL_SUCC_200.getCode();
        result.data = data;
        result.msg = "";
        return result;
    }

    public static <T> CommonResult<T> error(String code, String message) {
        CommonResult<T> result = new CommonResult<>();
        result.code = code;
        result.msg = message;
        return result;
    }
}
